package gui.client;


import gui.Player;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;

import javax.swing.JComponent;

import statics.Constants;

import net.protocols.ClientProtocol;


public class ClientRenderer extends JComponent implements MouseMotionListener, KeyListener{

	private Point mouse;
	private Player[] ps;
	private ClientProtocol prot;
	
	public ClientRenderer(Point start){
		mouse = new Point(0,0);
		ps = new Player[Constants._PLAYERS];
		setLayout(null);
		addMouseMotionListener(this);
	}
	
	public void addProtocol(ClientProtocol prot){
		this.prot = prot;
	}
	
	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
		
		for(Player p : ps){
			AffineTransform a = AffineTransform.getTranslateInstance(p.getX()-16, p.getY()-16);
			a.concatenate(AffineTransform.getRotateInstance(p.getTeta(mouse.x, mouse.y), 16, 16));
			g2d.drawImage(p.getIcon().getImage(),a,this);
		}
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		mouseMoved(arg0);
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		mouse.x = e.getX();
		mouse.y = e.getY();
		//Doorgeven aan Protocol
		repaint();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		//Doorgeven aan Protocol
	}

	@Override
	public void keyReleased(KeyEvent e) {
		//Doorgeven aan Protocol
	}

	@Override
	public void keyTyped(KeyEvent arg0) {}
	

	public Player getPlayer() {
		return null;
	}
	
	public int getMX(){
		return mouse.x;
	}
	
	public int getMY(){
		return mouse.y;
	}
	
}
